#include "rectEdges.hpp"
#include "rectMesh.hpp"

namespace hms
{

RectEdges::RectEdges( const RectMesh& mesh ) :
	StructEdgesBase<RectEdges>(mesh)
{}

auto RectEdges::lengthsImp() const -> LengthsReturnType {
	/* option 1: unaryExpr (doesn't work, because edgeIndices is a temporary) */
	// Index
	// 	ne { this->mesh().nEdges() },
	// 	nx { this->mesh().nCellsX() },
	// 	ng { this->mesh().nGhostLayers() },
	// 	nh { nHorizontalEdges( this->mesh().size() ) };
	
	// auto edgeIndices { ArrayXi::LinSpaced( ne, 0, ne-1 ) };
	// return
	// 	edgeIndices.unaryExpr( [&](Index i){
	// 		return i < nh ?
	// 			this->mesh().dx()(
	// 				i % nx + ng
	// 			) :
	// 			this->mesh().dy()(
	// 				(i-nh) / (nx+1) + ng
	// 			);
	// 	});

	/* option 2: concatenation */
	/* currently, this creates Eigen::Block expressions with InnerPanel=false.
	 * Given that the return type of d[x,y]Inner() is a VectorBlock, this
	 * may still be improved. */
	const Index
		nx { this->mesh().nCellsX() },
		ny { this->mesh().nCellsY() };

	return concat_vertical(
		this->mesh().dxInner().replicate(ny+1, 1).reshaped(),
		this->mesh().dyInner().transpose().replicate(nx+1, 1).reshaped()
	);
}


auto RectEdges::normalsImp() const -> NormalsReturnType {
	return rectNormals( this->mesh().size(), this->mesh().nEdges() );
}


} // namespace hms
